package com.zhongfl.crm.api.view;

import com.github.pagehelper.PageInfo;
import com.zhongfl.crm.model.crm.StaffExt;
import com.zhongfl.crm.request.RxStaffExt;
import com.zhongfl.crm.service.crm.StaffExtService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.heptagram.core.common.rest.ResponseResult;
import tech.heptagram.staff.cas.common.CurrentUserUtil;

import javax.annotation.Resource;

/**
 * @author 木叶丸
 * @date 2019/3/14 16:42
 */
@RestController
@RequestMapping("/api/view/staff/ext")
public class StaffExtApiController {

    @Resource
    private StaffExtService staffExtService;

    @PostMapping("/list")
    public ResponseResult<PageInfo<StaffExt>> findUserList(@RequestBody RxStaffExt rxStaffExt) {
        PageInfo<StaffExt> pageInfo = staffExtService.findByPage(rxStaffExt);
        return new ResponseResult<>(pageInfo);
    }

    @PostMapping("/updateBusinessDept")
    public ResponseResult updateBusinessDept(@RequestBody StaffExt staffExt) {
        String trueName = CurrentUserUtil.getCurrentUser().getTrueName();
        staffExt.setModifiedBy(trueName);
        staffExt.setCreatedBy(trueName);
        staffExtService.saveOrUpdateBusinessDept(staffExt);
        return new ResponseResult();
    }
}
